<!--
 * @Author: your name
 * @Date: 2021-08-25 10:40:27
 * @LastEditTime: 2021-08-25 19:15:59
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \briup\5-javascript\day03\3-this.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        //this在对象的内部去使用，指代自己
        var obj = {
            name: 'zs',
            age: 100,
            plus: function() {
                console.log('plus');
                console.log(obj, this); //this指代整个obj
            },
            sayName: function() {
                console.log(this.name); //this.name指代obj.name
            },
            updateAge: function(age) {
                this.age = age;
                console.log(this.age);
            }

        }

        //对象的外部
        console.log(obj, this, obj.name); //this不等于obj，外部的this是指浏览器
        obj.plus(); //函数调用，写在函数里的函数内容必须要调用才能执行
        obj.sayName();
        obj.updateAge(33);
        console.log(obj.age);




        //变量的作用域

        var num = 100;
        if (true) {
            var n2 = 200;
        }

        function fname() {
            var n3 = 300;
            console.log(n3);
        }
        console.log(n3); //外部不能访问内部的，输出结果!error
        console.log(obj.age, age); //100  !error
    </script>
</head>

<body>

</body>

</html>